import { ACOUNTAPIPREFIX, APIPCPREFIX, SYSTEMCODE } from '@/common';
import { request } from '../request';

/**
 * @desc 账号密码登录
 */

export const authLogin = (data: any) =>
  request({
    method: 'post',
    url: `${ACOUNTAPIPREFIX}/ent/user/api/account/authLogin.htm`,
    // headers: { 'Content-Type': 'application/json; charset=UTF-8' },
    data: { ...data, systemCode: 'logistics_cloud', verifyCode: '' },
    headers: {
      Clientsystem: 'Web',
      ClientType: 'WebEnt',
    },
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
  });

/**
 * @param data:{loginName,code,systemCode: 'logistics_cloud'}
 * @desc 验证码登录
 */

export const codeLogin = (data: any) =>
  request({
    method: 'post',
    url: ACOUNTAPIPREFIX + '/ent/user/api/account/codeLogin.htm',
    // headers: { 'Content-Type': 'application/json; charset=UTF-8' },
    data: { ...data, systemCode: SYSTEMCODE },
    headers: {
      Clientsystem: 'Web',
      ClientType: 'WebEnt',
    },
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
  });

/**
 * @params {mobile}
 * @desc 检查当前手机号平台是否拥有
 * @return {boolean} !res.suc && res.errCode === "005" 手机号平台已注册过, else 手机号平台未注册
 */
export const checkMobileIsRegistered = (params: any) =>
  request({
    method: 'get',
    url: ACOUNTAPIPREFIX + '/person/api/checkPhone.htm',
    params,
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
  });

/**
 * @params {mobile,type:1}
 * @desc 检查当天是否多次获取验证码(>=3)
 * @return {boolean} res.data=== true:当天多次获取验证码
 */
export const checkGetCodeMore = (params: any) =>
  request({
    method: 'get',
    url: ACOUNTAPIPREFIX + '/common/api/smsCode/exceedNumber',
    params,
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
  });

/**
 * @params {mobile}
 * @desc 获取已经验证的验证码次数
 * @return {boolean} res.data=== true:2次，false:首次获取
 */
export const getHasSendedCodeTimes = (params: any) =>
  request({
    method: 'get',
    url: ACOUNTAPIPREFIX + '/common/api/smsCode/secondLogin',
    params,
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
  });

/**
 * @desc 获取短信验证码
 */
export const getSMSCode = (data: any) =>
  request({
    method: 'post',
    url: ACOUNTAPIPREFIX + '/common/api/smsCode/getCode.htm',
    data,
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
    // headers: { 'Content-Type': 'application/json; charset=UTF-8' },
  });

/**
 * @desc 获取安全教育平台的token
 */
export const getSafeToken = (entId: string, personId: string) =>
  request({
    method: 'post',
    url: `${ACOUNTAPIPREFIX}/ent/user/api/account/getSafeToken.htm`,
    params: { entId, personId },
    noAutoShowErrorMessage: true,
    responseAsSuc: true,
  });

/**
 * @description 判断当前用户是否是超管
 */

export const getUserRole = (entId: string, personId: string) =>
  request({
    method: 'post',
    url: APIPCPREFIX + 'safeFee/distributionStudy/staffDetailsByPersonId',
    params: {
      entId,
      personId,
    },
  });
